package thinkinginjava.container;

interface Performancable {
	void run();
	String getDescription();
}

public class TimePerformance {
	public static final int DEFAULT_TIME = 10;
	
	public static void getNanoTime(Performancable per) {
		long s = System.nanoTime();
		per.run();
		System.out.println("Consumes " + (System.nanoTime() - s) + " ns[" + per.getDescription() + "]");
	}
	
	public static void getAvgNanoTime(Performancable per) {
		getAvgNanoTime(per, DEFAULT_TIME);
	}
	
	public static void getAvgNanoTime(Performancable per, int times) {
		long s = System.nanoTime();
		for(int i = 0; i < times; i ++)
			per.run();
		System.out.println("Consumes " + ((System.nanoTime() - s)/times) + " ns[" + per.getDescription() + "]");
	}
}
